using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bindings.Tests
{
    [TestClass]
    public class MyObject_does
    {
        private object O;
        private PropertyChangedEventArgs A;
        private MyObject MyObject;
        private object propChangingArg;


        [TestInitialize]
        public void SetUp()
        {
            O = null;
            A = null;
            MyObject = new MyObject();
        }


        [TestMethod]
        public void Announce_when_any_property_changes()
        {
            MyObject.PropertyChanged += (sender, args) =>
                                            {
                                                O = sender;
                                                A = args;
                                            };
            MyObject.SomeSimpleProperty = new object();
            Assert.AreSame(MyObject, O);
            Assert.AreEqual("SomeSimpleProperty", A.PropertyName);
        }


        [TestMethod]
        public void Makes_available_the_new_value_before_it_does_announce_the_change()
        {
            var newValue = new object();
            MyObject.PropertyChanged += (sender, args) =>
                                            {
                                                O = sender;
                                                A = args;
                                                Assert.AreSame(newValue, MyObject.SomeSimpleProperty);
                                            };
            MyObject.SomeSimpleProperty = newValue;
        }


        [TestMethod]
        public void Does_still_have_the_old_value_when_it_announces_that_it_is_about_to_change()
        {

            var oldValue = MyObject.SomeSimpleProperty;

            MyObject.PropertyChanging += (sender, args) =>
                                             {
                                                 O = sender;
                                                 propChangingArg = args;
												 Assert.AreSame(oldValue, MyObject.SomeSimpleProperty);
                                             };

			MyObject.SomeSimpleProperty = new object();



        }
    }
}